var path;
function initPath(ctx){
	path=ctx;
}
//区域修改连动 第一层
function areaChange(area){
	var text=$('#'+area+'').val();
	if(""==text){
		text=null;
		noDateCommon('city'); 
		return;
	}
	var d={area:text};
	var data =requestCommon(d);//查询数据
	 if(data!=null){
	       noDateCommon('knowledge_name');
		   for(var i in data.listzsd){
			   $('#knowledge_name').append("<option > "+data.listzsd[i]+"</option>");
		   }
		   noDateCommon('subject'); 
		   for(var i in data.listkm){
			   $('#subject').append("<option value='"+data.listkm[i]+"'> "+data.listkmName[i]+"</option>");
		   }
		   noDateCommon('semester'); 
		   for(var i in data.listxq){
			   $('#semester').append("<option value='"+data.listxq[i]+"'> "+xqChange(data.listxq[i])+"</option>");
		   }
		   noDateCommon('grade'); 
		   for(var i in data.listnj){
			   $('#grade').append("<option value='"+data.listnj[i]+"'> "+njChange(data.listnj[i])+"</option>");
		   }
		   noDateCommon('city'); 
		   for(var i in data.listcity){
			  if(data.listcity[i]!=""){
				  $('#city').append("<option value='"+data.listcity[i]+"'> "+data.listcity[i]+"</option>"); 
			  }
		   }
		}else{
			
			 noDateCommon('city');//清除数据
			 noDateCommon('knowledge_name');//清除数据
			 noDateCommon('subject');//没有数据
			 noDateCommon('semester');//没有数据
			 noDateCommon('grade');//没有数据
		}
}
function xqChange(km){
	var result="";
	switch (km) {
	case 1:
		result="上学期"
		break;
	case 2:
		result="下学期"
		break;
	}
	return result;
}
function grades(area,city,grade){
	var qy=$('#'+area+'').val();//区域
	if(''==qy){
		qy=null;
	}
	var city=$('#'+city+'').val();//城市
	if(''==city){
		city=null;
	}
	var nj=$('#'+grade+'').val();
	if(''==nj){
		nj=null;
	}
	var d={"area":qy,"grade":nj,"city":city};
	var data =requestCommon(d);//查询数据
	 if(data!=null){
		 noDateCommon('knowledge_name');
		   for(var i in data.listzsd){
			   $('#knowledge_name').append("<option > "+data.listzsd[i]+"</option>");
		   }
		   noDateCommon('subject'); 
		   for(var i in data.listkm){
			   $('#subject').append("<option value='"+data.listkm[i]+"'> "+data.listkmName[i]+"</option>");
		   }
		   noDateCommon('semester'); 
		   for(var i in data.listxq){
			   $('#semester').append("<option value='"+data.listxq[i]+"'> "+xqChange(data.listxq[i])+"</option>");
		   }
		}else{
			noDateCommon('knowledge_name');//清除数据
			 noDateCommon('subject');//没有数据
			 noDateCommon('semester');//没有数据
		}
}

function kemulink(area,city,grade,semester,subject){
	var qy=$('#'+area+'').val();//区域
	if(''==qy){
		qy=null;
	}
	var city=$('#'+city+'').val();//城市
	if(''==city){
		city=null;
	}
	var nj=$('#'+grade+'').val();
	if(''==nj){
		nj=null;
	}
	var xq=$('#'+semester+'').val();
	if(''==xq){
		xq=null;
	}
	var km=$('#'+subject+'').val();
	if(''==km){
		km=null;
	}
	var d={"area":qy,"grade":nj,"semester":xq,"subject":km,"city":city};
	var data =requestCommon(d);//查询数据
	 if(data!=null){
		 noDateCommon('knowledge_name');
		   for(var i in data.listzsd){
			   $('#knowledge_name').append("<option > "+data.listzsd[i]+"</option>");
		   }
		}else{
			noDateCommon('knowledge_name');//清除数据
		}
}
function xqlink(area,city,grade,semester){
	var qy=$('#'+area+'').val();//区域
	if(''==qy){
		qy=null;
	}
	var city=$('#'+city+'').val();//城市
	if(''==city){
		city=null;
	}
	var nj=$('#'+grade+'').val();
	if(''==nj){
		nj=null;
	}
	var xq=$('#'+semester+'').val();
	if('全部'==xq){
		xq=null;
	}
	var d={"area":qy,"grade":nj,"semester":xq,"city":city};
	var data =requestCommon(d);//查询数据
	 if(data!=null){
		 noDateCommon('knowledge_name');
		   for(var i in data.listzsd){
			   $('#knowledge_name').append("<option > "+data.listzsd[i]+"</option>");
		   }
		   noDateCommon('subject'); 
		   for(var i in data.listkm){
			   $('#subject').append("<option value='"+data.listkm[i]+"'> "+data.listkmName[i]+"</option>");
		   }
		}else{
			noDateCommon('knowledge_name');//清除数据
			 noDateCommon('subject');//没有数据
		}
	 
}
function cityQuery(area,city){
	var qy=$('#'+area+'').val();//区域
	if(''==qy){
		qy=null;
	}
	var city=$('#'+city+'').val();//城市
	if(''==city){
		city=null;
	}
	var d={"area":qy,"city":city};
	var data =requestCommon(d);//查询数据
	 if(data!=null){
		 noDateCommon('knowledge_name');
		   for(var i in data.listzsd){
			   $('#knowledge_name').append("<option > "+data.listzsd[i]+"</option>");
		   }
		   noDateCommon('subject'); 
		   for(var i in data.listkm){
			   $('#subject').append("<option value='"+data.listkm[i]+"'> "+data.listkmName[i]+"</option>");
		   }
		   noDateCommon('semester'); 
		   for(var i in data.listxq){
			   $('#semester').append("<option value='"+data.listxq[i]+"'> "+xqChange(data.listxq[i])+"</option>");
		   }
		   noDateCommon('grade'); 
		   for(var i in data.listnj){
			   $('#grade').append("<option value='"+data.listnj[i]+"'> "+njChange(data.listnj[i])+"</option>");
		   }
		}else{
			 noDateCommon('knowledge_name');//清除数据
			 noDateCommon('subject');//没有数据
			 noDateCommon('semester');//没有数据
			 noDateCommon('grade');//没有数据
		}	
}
function njChange(km){
	var result="";
	switch (km) {
	case 1:
		result="一年级"
		break;
	case 2:
		result="二年级"
		break;
	case 3:
		result="三年级"
		break;
	case 4:
		result="四年级"
		break;
	case 5:
		result="五年级"
		break;
	case 6:
		result="六年级"
		break;
	case 7:
		result="七年级"
		break;
	case 8:
		result="八年级"
		break;
	case 9:
		result="九年级"
		break;
	}
	return result;
}
function requestCommon(dat){
	var result=null;
	$.ajax({
		type:"post",
		url:path+"/questionLinkageList", 
		data:dat,
		dataType:"json",
		async:false,
		success:function(data){
			result=data;
			}
		});
	return result;
}
function noDateCommon(id){
	 var htm="<option value=''>全部</option>";
	 document.getElementById(id).length=0;   
	 $('#'+id+'').append("");
	 $('#'+id+'').append(htm);
}